package com.lookup.api;

import com.lookup.api.logger.LoggerWrapper;
import com.lookup.api.verticle.EventBusWorkerVerticle;
import com.lookup.api.verticle.HttpWorkerVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
import io.vertx.rxjava.core.AbstractVerticle;
import io.vertx.rxjava.core.Vertx;

import java.util.function.Consumer;

public class RxApiServer extends AbstractVerticle {

    private static LoggerWrapper logger = new LoggerWrapper("init.server" + RxApiServer.class.getName());
    private static final int CPUS = Runtime.getRuntime().availableProcessors();

    @Override
    public void start(Future<Void> startFuture) throws Exception {
        super.start(startFuture);
    }

    @Override
    public void start() throws Exception {

        Consumer<Vertx> runner = vertx -> {
            DeploymentOptions options = new DeploymentOptions();
            options.setInstances(CPUS);
            vertx.deployVerticle(HttpWorkerVerticle.class.getName(), options);
            vertx.deployVerticle(EventBusWorkerVerticle.class.getName(), options);
        };
        Vertx vertx = Vertx.vertx();
        runner.accept(vertx);

    }

    public static void main(String... args) {
        try {
            new RxApiServer().start();
        } catch (Exception e) {
            logger.error("  bootstrap error  ", e);
        }


    }


}
